package com.achievement.controller;

import com.achievement.domain.dto.PaperDTO;
import com.achievement.domain.dto.PaperIncludeDTO;
import com.achievement.domain.dto.PaperReshipDTO;
import com.achievement.domain.param.PaperParam;
import com.achievement.domain.vo.PaperVO;
import com.achievement.service.IPaperIncludeService;
import com.achievement.service.IPaperReshipService;
import com.achievement.service.IPaperService;
import com.common.annotation.Anonymous;
import com.common.annotation.Log;
import com.common.core.controller.BaseController;
import com.common.core.domain.AjaxResult;
import com.common.core.page.TableDataInfo;
import com.common.enums.BusinessType;
import com.common.utils.poi.ExcelUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.List;

/**
 * PaperController
 * 成果管理，科研成果，学术论文
 */

@RestController
@RequestMapping("/achievement/paper")
@Api(tags = "成果管理模块---学术论文")
public class PaperController  extends BaseController {

    @Autowired
    private IPaperService paperService;

    @Autowired
    private IPaperReshipService paperReshipService;

    @Autowired
    private IPaperIncludeService paperIncludeService;

    /**
     * 获取论文详细信息
     */
    @PreAuthorize("@ss.hasPermi('achievement:paper:query')")
    @ApiOperation(value = "获取论文详细信息",notes = "获取论文详细信息")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(paperService.getInfoById(id));
    }

    /**
     * 新增论文基本信息及作者信息
     */
    @PreAuthorize("@ss.hasPermi('achievement:paper:add')")
    @Log(title = "新增论文基本信息及作者信息", businessType = BusinessType.INSERT)
    @ApiOperation(value = "新增论文基本信息及作者信息",notes = "新增论文基本信息及作者信息")
    @PostMapping(value = "/add")
    public AjaxResult add(@RequestBody PaperDTO dto)
    {
        return paperService.add(dto);
    }

    /**
     * 删除论文
     */
    @PreAuthorize("@ss.hasPermi('achievement:paper:remove')")
    @Log(title = "删除论文", businessType = BusinessType.DELETE)
    @ApiOperation(value = "删除论文",notes = "删除论文")
    @DeleteMapping("/del/{ids}")
    public AjaxResult remove(@PathVariable List<String> ids)
    {
        return toAjax(paperService.batchRemove(ids));
    }

    /**
     * 修改论文
     */
    @PreAuthorize("@ss.hasPermi('achievement:paper:edit')")
    @Log(title = "修改论文", businessType = BusinessType.UPDATE)
    @ApiOperation(value = "修改论文",notes = "修改论文")
    @PostMapping(value = "/update")
    public AjaxResult edit(@RequestBody PaperDTO dto)
    {
        return paperService.update(dto);
    }

    /**
     * 列表检索
     */
    @PreAuthorize("@ss.hasPermi('achievement:paper:list')")
    @Log(title = "列表检索")
    @ApiOperation(value = "列表检索",notes = "列表检索")
    @GetMapping("/list")
    public TableDataInfo list(PaperParam param)
    {
        startPage();
        List<PaperVO> list = paperService.selectByPage(param);
        return getDataTable(list);
    }

    /**
     * 论文导出
     */
    @PreAuthorize("@ss.hasPermi('achievement:paper:export')")
    @Log(title = "论文导出", businessType = BusinessType.EXPORT)
    @ApiOperation(value = "论文导出",notes = "论文导出")
    @PostMapping("/export")
    public void export(HttpServletResponse response,@RequestBody  PaperParam param)
    {
        List<PaperVO> list = paperService.selectByExport(param);
        List<String> selectedColumns = param.getExcelColumn();
        ExcelUtil<PaperVO> util = new ExcelUtil<>(PaperVO.class);
        util.showColumn(selectedColumns.toArray(new String[0]));
        util.exportExcelByOrder(response, list, "论文清单",selectedColumns.toArray(new String[0]));
    }

    /**
     * 左上方统计 通过，退回，待审核
     * @param param 检索参数
     * @return AjaxResult
     */
    @PreAuthorize("@ss.hasPermi('achievement:paper:list')")
    @ApiOperation(value = "左上方统计 通过，退回，待审核",notes = "左上方统计 通过，退回，待审核")
    @GetMapping(value = "/list-statistics")
    public AjaxResult listStatistics(PaperParam param)
    {
        List<HashMap<String, Integer>> list =paperService.listStatistics(param);

        return success(list);
    }

    /**
     * 新增论文转载情况
     */
    @PreAuthorize("@ss.hasPermi('achievement:paper:add')")
    @Log(title = "新增论文转载情况", businessType = BusinessType.INSERT)
    @ApiOperation(value = "新增论文转载情况",notes = "新增论文转载情况")
    @PostMapping(value = "/addPaperReship")
    public AjaxResult addPaperReship(@RequestBody PaperReshipDTO dto) {
        return toAjax(paperReshipService.addPaperReship(dto));
    }

    /**
     * 编辑论文转载情况
     */
    @PreAuthorize("@ss.hasPermi('achievement:paper:edit')")
    @Log(title = "编辑论文转载情况", businessType = BusinessType.UPDATE)
    @ApiOperation(value = "编辑论文转载情况",notes = "编辑论文转载情况")
    @PostMapping(value = "/editPaperReship")
    public AjaxResult editPaperReship(@RequestBody PaperReshipDTO dto) {
        return toAjax(paperReshipService.editPaperReship(dto));
    }

    /**
     * 删除论文转载情况
     */
    @PreAuthorize("@ss.hasPermi('achievement:paper:remove')")
    @Log(title = "删除论文转载情况", businessType = BusinessType.DELETE)
    @ApiOperation(value = "删除论文转载情况",notes = "删除论文转载情况")
    @DeleteMapping("/delPaperReship/{id}")
    public AjaxResult delPaperReship(@PathVariable("id") String id)
    {
        return toAjax(paperReshipService.delPaperReship(id));
    }

    /**
     * 根据论文id，查询转载情况列表
     */
    @PreAuthorize("@ss.hasPermi('achievement:paper:query')")
    @Log(title = "根据论文id，查询转载情况列表")
    @ApiOperation(value = "根据论文id，查询转载情况列表",notes = "根据论文id，查询转载情况列表")
    @GetMapping(value = "/paperReship/{id}")
    public AjaxResult getPaperReshipInfo(@PathVariable("id") String id) {
        return success(paperReshipService.getInfoById(id));
    }

    /**
     * 新增论文收录信息
     */
    @PreAuthorize("@ss.hasPermi('achievement:paper:add')")
    @Log(title = "新增论文收录信息", businessType = BusinessType.INSERT)
    @ApiOperation(value = "新增论文收录信息",notes = "新增论文收录信息")
    @PostMapping(value = "/addPaperInclude")
    public AjaxResult addPaperInclude(@RequestBody PaperIncludeDTO dto)
    {
        return toAjax(paperIncludeService.addPaperInclude(dto));
    }

    /**
     * 编辑论文收录信息
     */
    @PreAuthorize("@ss.hasPermi('achievement:paper:edit')")
    @Log(title = "编辑论文收录信息", businessType = BusinessType.UPDATE)
    @ApiOperation(value = "编辑论文收录信息",notes = "编辑论文收录信息")
    @PostMapping(value = "/editPaperInclude")
    public AjaxResult editPaperInclude(@RequestBody PaperIncludeDTO dto) {
        return toAjax(paperIncludeService.editPaperInclude(dto));
    }

    /**
     * 删除论文收录信息
     */
    @PreAuthorize("@ss.hasPermi('achievement:paper:remove')")
    @Log(title = "删除论文收录信息", businessType = BusinessType.DELETE)
    @ApiOperation(value = "删除论文收录信息",notes = "删除论文收录信息")
    @DeleteMapping("/delPaperInclude/{id}")
    public AjaxResult delPaperInclude(@PathVariable String id) {
        return toAjax(paperIncludeService.delPaperInclude(id));
    }

    /**
     * 根据论文id，查询论文收录信息列表
     */
    @PreAuthorize("@ss.hasPermi('achievement:paper:query')")
    @Log(title = "根据论文id，查询论文收录信息列表")
    @ApiOperation(value = "根据论文id，查询论文收录信息列表",notes = "根据论文id，查询论文收录信息列表")
    @GetMapping(value = "/paperInclude/{id}")
    public AjaxResult getPaperIncludeInfo(@PathVariable("id") String id) {
        return success(paperIncludeService.getInfoById(id));
    }

}
